<template>
  <div>
    <el-card shadow="always">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-date-picker
            style="width: 300px"
            v-model="value1"
            type="daterange"
            range-separator="至"
            start-placeholder="浏览开始日期"
            @change="change"
            value-format="yyyy-MM-dd"
            end-placeholder="浏览结束日期"
          >
          </el-date-picker>
        </el-col>
         <el-col :span="4">
          <el-input
            clearable
            maxlength="50"
            v-model="query.tabulationUnitName"
            placeholder="请输入单位名称"
          ></el-input>
        </el-col>
        <el-col :span="2">
          <el-button
            type="primary"
            @click="
              getList();
              query.pageIndex = 1;
            "
            >查询</el-button
          ></el-col
        >
      </el-row>
      <rz-height></rz-height>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column
          prop="theName"
          label="联系人"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="mobile"
          label="联系电话"
          width="200"
        ></el-table-column>
        <el-table-column prop="unitName" label="单位名称">
          <template slot-scope="scope">
            <div v-if="scope.row.unitName === '匿名'">
              {{ scope.row.unitName }}
            </div>
            <div class="active" @click="detail(scope.row.unitName)" v-else>
              {{ scope.row.unitName }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="illustrate"
          label="统一信用代码"
        ></el-table-column>
        <el-table-column
          prop="createDate"
          label="最新浏览日期"
          width="180"
        ></el-table-column>
        <el-table-column
          prop="numberOfTimes"
          label="浏览次数"
          width="100"
        ></el-table-column>
      </el-table>
      <pagination
        :total="total"
        @pagination="getList"
        :page.sync="query.pageIndex"
      />
    </el-card>

    <el-dialog
      title="登录"
      :visible.sync="dialogVisible"
      width="400px"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :show-close="false"
    >
      <el-form ref="form" :model="form" label-width="0" :rules="rules">
        <el-form-item prop="mobile">
          <el-input
            v-model="form.mobile"
            maxlength="11"
            placeholder="请输入手机号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="cipher">
          <el-input
            v-model="form.cipher"
            type="password"
            placeholder="请输入密码"
            maxlength="18"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit" style="width: 100%"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      title="查看详情"
      :visible.sync="active"
      width="80%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
    >
      <el-table :data="tableList" border style="width: 100%">
        <el-table-column
          prop="theName"
          label="联系人"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="mobile"
          label="联系电话"
          width="200"
        ></el-table-column>
        <el-table-column prop="unitName" label="单位名称">
        </el-table-column>
        <el-table-column
          prop="illustrate"
          label="统一信用代码"
        ></el-table-column>
        <el-table-column
          prop="createDate"
          label="最新浏览日期"
          width="180"
        ></el-table-column>
        <!-- <el-table-column
          prop="numberOfTimes"
          label="浏览次数"
          width="100"
        ></el-table-column> -->
      </el-table>
      <pagination
        :total="total1"
        @pagination="activeList"
        :page.sync="sendQuery.pageIndex"
      />
      <span slot="footer" class="dialog-footer">
    <el-button @click="active = false">关 闭</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  landSupplierPromotionForm,
  SunshineCanteenRecordList,
} from "@/api/modules/enterprise";
import Vue from "vue";
export default {
  // props:[],
  // 页面加载
  created() {
    // this.getList();
    if (this.$formValidate && this.$formValidate.mobile) {
      this.dialogVisible = false;
      landSupplierPromotionForm({
        params: this.$formValidate,
      }).then((res) => {
        this.getList();
      });
    }
  },
  // 页面加载完成
  mounted() {},
  //实例销毁之前
  beforeDestroy() {},
  //实例销毁后
  destroyed() {},
  data() {
    return {
      query: {
        pageIndex: 1,
        pageSize: 10,
        shareDateEnd: "",
        shareDateStart: "",
        	"tabulationUnitName": ""
      },
      sendQuery: {
        pageIndex: 1,
        pageSize: 10,
        shareDateEnd: "",
        shareDateStart: "",
        unitName: "",
      },
      tableData: [],
      dialogVisible: true,
      total: 0,
      form: {
        mobile: "",
        cipher: "",
      },
      rules: {
        mobile: [{ required: true, message: "请输入手机号", trigger: "blur" }],
        cipher: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      value1: [],
      active: false,
      tableList:[],
            total1: 0,
    };
  },
  // 方法
  methods: {
    getList() {
      landSupplierPromotionForm({
        params: this.$formValidate,
      }).then((res) => {
        SunshineCanteenRecordList(this.query).then((res) => {
          this.tableData = res.data.list;
          this.total = res.totalCount;
        });
      });
    },
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          landSupplierPromotionForm({
            params: this.form,
          }).then((res) => {
            this.$success(res.msg);
            Vue.prototype.$formValidate = this.form;
            this.getList();
            this.dialogVisible = false;
          });
        }
      });
    },
    change(e) {
      if (e) {
        this.query.shareDateStart = e[0];
        this.query.shareDateEnd = e[1];
      } else {
        this.query.shareDateStart = "";
        this.query.shareDateEnd = "";
      }
    },
    detail(unitName) {
      this.sendQuery.unitName=unitName
    this.activeList()
      this.active = true;
    },
    activeList(){
         landSupplierPromotionForm({
        params: this.$formValidate,
      }).then((res) => {
      SunshineCanteenRecordList(this.sendQuery).then((res) => {
          this.tableList = res.data.list;
          this.total1 = res.totalCount;
        });
        });
    },
  },
  // 监听属性
  watch: {},
  // 组件
  components: {},
  // 计算属性
  computed: {},
};
</script>

<style lang="scss" scoped>
.active {
  color: $default;
  text-decoration: underline;
  cursor: pointer;
}
</style>